<?php
/**
 * Created by PhpStorm.
 */

namespace backend\service;


use backend\component\BackendBaseService;
use backend\component\ResultEasyUIFormat;
use backend\component\ResultFormat;
use common\models\info\Album;
use common\models\info\Photo;

class PhotoService extends BackendBaseService
{
    public static function PhotoList($get,$page=1,$pageSize=10) {
        $model = new Photo();
        $result = $model->getAllList($get,$page,$pageSize);
        $row = Album::findOne($get['id']);
        $result['one'] = $row->attributes;
        return json_encode($result);
    }
    public static function removePhotos($ids) {
        $model = new Photo();
       $model->removePhoto($ids);
        return ResultFormat::success("删除成功");
    }
    public static function getPhotoById($get){
        $row = Photo::findOne($get['id']);
        $result = $row->attributes;
        return ResultFormat::success('SUCCESS',$result);
    }
    public static function modifyPhoto($get,$params){
            $model =Photo::modelById($get['id']);
                    $model->setAttributes($params);
                    if (!$model->save()) {
                        return ResultFormat::error($model->getErrorsToString());
                    }
                    return ResultFormat::success("操作成功");
    }
    public static function setPhoto($get){
        $album_id = $get['album_id'];
        $row = Photo::findOne($get['id']);
        $result = $row->attributes;
        $url = $result['url'];
        $model =Album::findOne($album_id);
        $model->url = $url;
      if(!$model->update()){
          return ResultFormat::error($model->getErrorsToString());
      }
        return ResultFormat::success("操作成功");
    }
    public static function movePhoto($get){
        $id = $get['id'];
        $poto_id =$get['photoId'];
      return Photo::updatePhoto($poto_id,$id);
    }

}
